package org.imsetal.iluserservice.controller;

import jakarta.annotation.Resource;
import org.imsetal.ilapi.utils.Result;
import org.imsetal.iluserservice.service.UserService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("register")
public class RegisterController {
    @Resource
    UserService userService;

    @PostMapping("")
    public Result register(String username, String userpassword) {
        String info=userService.register(username, userpassword);
        if(info.equals("success")) {
            Map<String,String> resultmsg=new HashMap<>();
            resultmsg.put("info",info);
            resultmsg.put("token",userService.createUserLoginToken(username,userpassword));
            return Result.success(resultmsg);
        }
        else return Result.error("100",info);
    }
}
